import {createRouter, createWebHashHistory} from 'vue-router'

//正常的引入路由组件没有赖加载
/*
import Home from "@/components/Home.vue";
import Login from "@/components/Login.vue";
import Register from "@/components/Register.vue";
*/

//路由赖加载
const Home = () => import("../components/Home.vue")
const Login = () => import("../components/Login.vue")
const Register = () => import("../components/Register.vue")

const Goods = () => import("../components/Goods.vue")
const Person = () => import("../components/Person.vue")
const routes = [
    // 一级路由
    {
        path: "/",
        redirect: "/home"
    },
    {
        path: "/home",
        name: "home",
        component: Home,
        // Home组件下的二级路由
        children: [
            {path: 'person', component: Person},
            {path: 'goods', component: Goods},
        ]
    },
    {
        path: "/login",
        name: "login",
        component: Login
    },
    {
        path: "/register",
        name: "register",
        component: Register
    },

]

const router = createRouter({
    history: createWebHashHistory(),
    routes
})
//全局前置守卫
router.beforeEach((to, from, next) => {

})
//动态添加路由
let isAdmin = true
if (isAdmin) {
    router.addRoute({
        path: "/admin",
        component: Admin,
    })
}
export default router
